import { Injectable } from '@angular/core'
import { computed, observable } from 'mobx-angular'

const OPONENT = {
  X: 'O',
  O: 'X',
}

@Injectable()
export class GameStore {
  @observable board: string[][]
  @observable score = { X: 0, O: 0 }
  @observable firstPlayer = 'X'

  @computed get currentPlayer(): string {
    return this.moves % 2 ? OPONENT[ this.firstPlayer ] : this.firstPlayer
  }

  @computed get moves() {
    return this.board[ 0 ].filter(v => v).length +
      this.board[ 1 ].filter(v => v).length +
      this.board[ 2 ].filter(v => v).length
  }
}
